home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / comm / net / grapevine.lha / Grapevine / DCC-Send-1.12.lha / DCC / ProcessFile.rexx < prev    next >
OS/2 REXX Batch file  |  1995-01-30  |  7KB  |  220 lines

  1. /* $VER: ProcessFile.rexx 0.13 (4.12.94) 
  2.  * process a file according to the extension */
  3. /* Authors Osma Ahvenlampi, Michael Van Elst, Dan Murrell Jr. 
  4.  * View a file after de-archiving enhancement by Alejandro Garza */
  5.  
  6. /* This is the program used to view the file if no match is found */
  7. file.default = "SYS:Utilities/MultiView"
  8.  
  9. /* If this is set to 1, the user will be asked whether he wants to delete
  10.  * the file after it has been processed */
  11. file.delete = 1
  12.  
  13. /* If this is set to 1, the user will be prompted if he/she wants to view
  14.  * any of the files in the archive after unpacking */
  15. file.arcview = 1
  16.  
  17. /* list of supported archivers */
  18. file.archive = "LHA LZH GZ Z ZIP"
  19.  
  20. /* where you would like the archive unpacked by default */
  21. file.unpackdir = "RAM:"
  22.  
  23. /* full paths to known (un)packers */
  24. archiver.lha = "LhA"
  25. archiver.gzip = "GZip"
  26. archiver.zip = "UnZip"
  27.  
  28. /* next is the list of extensions and the programs used to show them
  29.  * list the extensions in upper case */
  30. file.1.type = "ILBM HAM GIF"
  31. file.1.viewer = "FastView >NIL:"
  32. file.2.type = "WAV AU 8SVX"
  33. file.2.viewer = "Play16 >NIL:" /* LOTS better than OPlay... */
  34. file.3.type = "JPG JPEG"
  35. file.3.viewer = "SYS:Utilities/FJPEG >NIL:"
  36. file.4.type = "GUIDE TXT DOC"
  37. file.4.viewer = "SYS:Utilities/MultiView"
  38. file.5.type = "MOD MED"
  39. file.5.viewer = "SYS:Utilities/Player NODETACH MODULES"
  40. file.6.type = "MPG MPEG"
  41. file.6.viewer = "mp -dither ham6"
  42.  
  43. /* this is the number of the last type */
  44. file.num = 6
  45.  
  46. /* get filename */
  47. parse arg '"' completename '"' '"' pubscreen '"'
  48.  
  49. if completename="" then
  50.     parse arg completename
  51.  
  52. if ~exists(completename) then exit
  53.  
  54. if pubscreen="" then
  55.     pubscreen = "Workbench"
  56.  
  57. viewed = 0
  58. processed = 0
  59.  
  60. if ~show(l, 'rexxsupport.library') then do
  61.     if ~addlib('rexxsupport.library', 0, -30) then do
  62.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File Error" BODY="Could not execute macro*nlibs:rexxsupport.library not found" GADGETS="OK" >NIL:'
  63.         exit 10
  64.     end
  65. end
  66.  
  67. call CheckExt
  68.  
  69. /* test it against known archivers/packers */
  70. if (extension ~= "") & (find( file.archive, extension ) > 0) then do
  71.     viewed = 1
  72.     call UnPack
  73. end
  74.  
  75. /* test it against known file types */
  76. if ~viewed & (extension ~= "") then
  77.     do i = 1 to file.num while ~viewed
  78.         if find( file.i.type, extension ) > 0 then do
  79.             viewed = 1
  80.             address command file.i.viewer '"'completename'"'
  81.             if rc = 0 then
  82.                 processed = 1
  83.         end
  84.     end
  85.  
  86. if ~viewed then do
  87.     /* if the type wasn't recognised, try the default viewer on it */
  88.     address command file.default '"'completename'"'
  89.     if rc = 0 then
  90.         processed = 1
  91. end
  92.  
  93. call DeleteFile
  94.     
  95. exit
  96.  
  97. UnPack:
  98.     if (extension = "LHA") | (extension = "LZH") then do
  99.         address command 'LhA v "'completename'" >T:LhaContents.tmp'
  100.         address command file.default 'T:LhaContents.tmp'
  101.         address command 'C:Delete >NIL: T:LhaContents.tmp'
  102.  
  103.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Un-LHA file 'completename'?" GADGETS="Yes|No" >T:reqchoice.unlha'
  104.     
  105.         call open(choicefile, 'T:reqchoice.unlha', 'R')
  106.         answer = readch(choicefile, 1)
  107.         call close(choicefile)
  108.         address command 'C:Delete >NIL: T:reqchoice.unlha'
  109.  
  110.         if answer = '1' then do
  111.             address command 'C:RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer'
  112.  
  113.             call open(choicefile, 'T:req.drawer', 'R')
  114.             file.unpackdir = readln(choicefile)
  115.             call close(choicefile)
  116.             address command 'C:Delete >NIL: T:req.drawer'
  117.     
  118.             if length(answer) > 0 then do
  119.                 address command archiver.lha 'x "'completename'" 'file.unpackdir
  120.                 processed = 1
  121.             end
  122.         end
  123.     end
  124.  
  125.     if (extension = "ZIP") then do
  126.         address command 'C:UnZIP -v "'completename'" >T:ZIPContents.tmp'
  127.         address command file.default 'T:ZIPContents.tmp'
  128.         address command 'C:Delete >NIL: T:ZIPContents.tmp'
  129.  
  130.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="UnZIP file 'completename'?" GADGETS="Yes|No" >T:reqchoice.unZIP'
  131.  
  132.         call open(choicefile, 'T:reqchoice.unZIP', 'R')
  133.         answer = readch(choicefile, 1)
  134.         call close(choicefile)
  135.         address command 'C:Delete >NIL: T:reqchoice.unZIP'
  136.  
  137.         if answer = '1' then do
  138.             address command 'C:RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer'
  139.  
  140.             call open(choicefile, 'T:req.drawer', 'R')
  141.             file.unpackdir = readln(choicefile)
  142.             call close(choicefile)
  143.             address command 'C:Delete >NIL: T:req.drawer'
  144.     
  145.             if length(answer) > 0 then do
  146.                 address command archiver.zip '"'completename'" -d 'file.unpackdir
  147.                 processed = 1
  148.             end
  149.         end
  150.     end
  151.     
  152.     /* Ask if the user wants to view any of the files, if file.arcview == 1 */
  153.     if processed & file.arcview then do
  154.         call DeleteFile
  155.         file.delete = 0        /* don't touch the unpacked files... */
  156.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="View a file from the archive?" GADGETS="Yes|No" >T:reqchoice.arcview'
  157.  
  158.         call open(choicefile, 'T:reqchoice.arcview', 'R')
  159.         answer = readln(choicefile)
  160.         call close(choicefile)
  161.         address command 'C:Delete >NIL: T:reqchoice.arcview'
  162.  
  163.         if answer = '1' then do
  164.             address command 'C:RequestFile DRAWER='file.unpackdir' TITLE="Choose file to view" NOICONS PUBSCREEN="'pubscreen'" >T:req.arcfile'
  165.  
  166.             call open(choicefile, 'T:req.arcfile', 'R')
  167.             answer = readln(choicefile)
  168.             call close(choicefile)
  169.             address command 'C:Delete >NIL: T:req.arcfile'
  170.  
  171.             parse var answer '"'completename'"'
  172.             call CheckExt
  173.             viewed = 0
  174.             processed = 0
  175.         end
  176.         return
  177.     end
  178.     
  179.     if (extension = "GZ") | (extension = "Z") then do
  180.         address command archiver.gzip '-d "'completename'"'
  181.         viewed = 0
  182.         completename = filename
  183.         call CheckExt
  184.     end
  185.  
  186.     return
  187.  
  188. CheckExt:
  189.     /* find position of the last period, if any, to set off the file extension */
  190.     dot = lastpos(".", completename)
  191.  
  192.     if (dot > 0) then do
  193.         /* there is an extension.. put it in another variable and make it upper case */
  194.         filename = left(completename, dot-1)
  195.         extension = upper(substr(completename, dot+1))
  196.     end
  197.     else do
  198.         filename = completename
  199.         extension = ""
  200.     end
  201.  
  202.     return
  203.  
  204. DeleteFile:
  205.     if processed & file.delete & exists(completename) then do 
  206.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Delete file 'completename'?" GADGETS="Yes|No" >T:reqchoice.delete'
  207.     
  208.         call open(choicefile, 'T:reqchoice.delete', 'R')
  209.         answer = readch(choicefile, 1)
  210.         call close(choicefile)
  211.         address command 'C:Delete >NIL: T:reqchoice.delete'
  212.         
  213.         if answer = '1' then do
  214.             address command 'C:Delete >NIL: "'completename'"'
  215.     /*        address command 'C:RequestChoice >NIL: PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="'completename' deleted" GADGETS="OK"' */
  216.         end
  217.     end
  218.  
  219.     return
  220.